<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport"
	content="width=device-width, initial-scale=1, maximum-scale=1">
<title>系统信息</title>
<#include "/include/head.html">
<style>
.layui-form-item .layui-input-inline {
    width: 300px;
}
.layui-form-label {
	width: 100px;
}
.layui-input-block{
	margin-left: 130px;
}
</style>
</head>
<body>

	<div class="layui-tab layui-tab-brief">
		<ul class="layui-tab-title">
			<li class="layui-this">系统信息</li>
			<li>图表</li>
			<li>进程</li>
		</ul>
		<div class="layui-tab-content">
			<div class="layui-tab-item layui-show">
				<#include "/system/systeminfo.html">
			</div>
			<div class="layui-tab-item">
				<#list eths as item>
				<#if (item.name != "lo")>
				<fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
				  <legend><span id="eth-host-${item.name!}"></span>${item.name!}</legend>
					<div class="layui-form-item">
						<div class="layui-inline">
							<div id="down-${item.name!}" style="width: 350px;height:350px;"></div>
						</div>
						<div class="layui-inline">
							<div id="up-${item.name!}" style="width: 350px;height:350px;"></div>
						</div>
					</div>
				</fieldset>  
				</#if>
				</#list>
			</div>
			<div class="layui-tab-item">
				CPU:
				<div class="layui-progress layui-progress-big" lay-showPercent="true">
			    	<div id="cpu" class="layui-progress-bar layui-bg-blue" lay-percent="0%"></div>
			    </div>
				物理内存:
				<div class="layui-progress layui-progress-big" lay-showPercent="true">
			    	<div id="mem" class="layui-progress-bar layui-bg-blue" lay-percent="0%"></div>
			    </div>
				Swap：
				<div class="layui-progress layui-progress-big" lay-showPercent="true">
			    	<div id="swap" class="layui-progress-bar layui-bg-blue" lay-percent="0%"></div>
			    </div>
				<table id="table" lay-size="sm" class="layui-hide" lay-filter="table"></table>
			</div>
		</div>
		
	</div>

	<#include "/include/end.html"> 
	<script src="/components/echarts/echarts.min.js"></script>
	<script type="text/html" id="toolbar">
	<div class="layui-btn-group">
	  	<button class="layui-btn layui-btn-sm layui-btn-normal" lay-event="refresh-opt">
		<i class="layui-icon">&#xe669;</i> 刷新
  		</button>
  	</div>
	</script>
	<script type="text/html" id="optbar">
  		<a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="view-opt">查看</a>
	</script>
	<script>
		layui.use(['element','layer','table'], function() {
			var element = layui.element,
			layer = layui.layer,
			table = layui.table,
			$ = layui.$;
			//----tips-----
			$('input.layui-input').click(function(){
				layer.tips($(this).attr('tips'), $(this), {
					  tips: [1, '#3595CC'],
					  time: 2000
					});
			});
			//----tips-----
			<#list eths as item>
			<#if (item.name != "lo")>
			var downChart = echarts.init(document.getElementById('down-${item.name!}'));
			var upChart = echarts.init(document.getElementById('up-${item.name!}'));
			var downOption_${item.name!} = {
				    tooltip: {
				        formatter: '{a} <br/>{b} : {c}Mib'
				    },
				    series: [
				        {
				            name: '下行速度',
				            type: 'gauge',
				            min: 0,
				            max: 1000,
				            detail: {formatter: '{value}Mib/s',fontSize: 10},
				            data: [{value: 0, name: '下行速度'}]
				        }
				    ]
				};
			var upOption_${item.name!} = {
				    tooltip: {
				        formatter: '{a} <br/>{b} : {c}Mib'
				    },
				    series: [
				        {
				            name: '上行速度',
				            type: 'gauge',
				            min: 0,
				            max: 1000,
				            detail: {formatter: '{value}Mib/s',fontSize: 10},
				            data: [{value: 0, name: '上行速度'}]
				        }
				    ]
				};
			downChart.setOption(downOption_${item.name!},true);
			upChart.setOption(upOption_${item.name!},true);
			</#if>
			</#list>
			var tableObj = table.render({
		    	  id: 'main-table',
		    	  elem: '#table', //指定原始表格元素选择器（推荐id选择器）
		    	  url: '/boss/linux/top',
		    	  method:'post',
		    	  autoSort : false,
		    	  size: 'sm',
				  even: true,
		    	  toolbar: '#toolbar',
		    	  height: 'full-190',
		    	  page: false,
		    	  cols: [[
		    		  {type:'numbers'},
		    		  {field: 'pid', title: '进程ID',sort:true,width:150,templet: function(d){
		    			  switch(d.pid) {
		    			  	case null:
		    			  		return '--';
		    			  	case '':
		    			  		return '';
		    			  	default:
		    			  		return d.pid;
		    			  }
		    	      }},
		    		  {field: 'command', title: '命令',sort:true,width:150,templet: function(d){
		    			  switch(d.command) {
		    			  	case null:
		    			  		return '--';
		    			  	case '':
		    			  		return '';
		    			  	case 'java':
		    			  		return '<a class="layui-badge layui-bg-orange" href="javascript:;">'+d.command+'</a>';
		    			  	default:
		    			  		return '<a href="https://www.baidu.com/baidu?wd='+d.command+'" target="_blank">'+d.command+'</a>';
		    			  }
		    	      }},
		    		  {field: 'res', title: '常驻内存',sort:true,width:150,templet: function(d){
		    			  switch(d.res) {
		    			  	case null:
		    			  		return '--';
		    			  	case '':
		    			  		return '';
		    			  	default:
		    			  		if(isNum(d.res)){
			    			  		return (d.res/1024).toFixed(2)+' M';
		    			  		} else {
			    			  		return d.res;
		    			  		}
		    			  }
		    	      }},
		    		  {field: 'virt', title: '虚拟内存',sort:true,width:150,templet: function(d){
		    			  switch(d.virt) {
		    			  	case null:
		    			  		return '--';
		    			  	case '':
		    			  		return '';
		    			  	default:
		    			  		if(isNum(d.virt)){
			    			  		return (d.virt/1024).toFixed(2)+' M';
		    			  		} else {
			    			  		return d.virt;
		    			  		}
		    			  }
		    	      }},
		    		  {field: 's', title: '进程状态',sort:false,width:150,templet: function(d){
		    			  switch(d.s) {
		    			  	case null:
		    			  		return '--';
		    			  	case 'S':
		    			  		return '<span class="layui-badge layui-bg-gray">睡眠</span>';
		    			  	case 'R':
		    			  		return '<span class="layui-badge layui-bg-green">运行</span>';
		    			  	case 'T':
		    			  		return '跟踪/停止';
		    			  	case 'Z':
		    			  		return '僵尸进程';
		    			  	case 'D':
		    			  		return '不可中断的睡眠';
		    			  	default:
		    			  		return d.s;
		    			  }
		    	      }},
		    		  {field: 'cpu', title: 'CPU使用率',sort:false,width:150,templet: function(d){
		    			  switch(d.cpu) {
		    			  	case null:
		    			  		return '--';
		    			  	default:
		    			  		return d.cpu+'%';
		    			  }
		    	      }},
		    		  {field: 'mem', title: '内存使用率',sort:false,width:150,templet: function(d){
		    			  switch(d.mem) {
		    			  	case null:
		    			  		return '--';
		    			  	default:
		    			  		return d.mem+'%';
		    			  }
		    	      }},
		    		  {field: 'read', title: '磁盘读(Kb/s)',sort:false,width:100,templet: function(d){
		    			  switch(d.read) {
		    			  	case null:
		    			  		return '--';
		    			  	default:
		    			  		return d.read;
		    			  }
		    	      }},
		    	      {field: 'write', title: '磁盘写(Kb/s)',sort:false,width:100,templet: function(d){
		    			  switch(d.write) {
		    			  	case null:
		    			  		return '--';
		    			  	default:
		    			  		return d.write;
		    			  }
		    	      }},
		    	      {field: 'user', title: '用户',sort:false,width:150,templet: function(d){
		    			  switch(d.user) {
		    			  	case null:
		    			  		return '--';
		    			  	default:
		    			  		return d.user;
		    			  }
		    	      }},
		    		  {field: 'time', title: '使用CPU时间',sort:false,width:150,templet: function(d){
		    			  switch(d.time) {
		    			  	case null:
		    			  		return '--';
		    			  	default:
		    			  		return d.time;
		    			  }
		    	      }},
		    	      {fixed: 'right', title:'操作', toolbar: '#optbar', width:165}
		    	  ]],
		    	  parseData: function(res){
		    		  //$('#cpu').attr('lay-percent',(res.cpuUser+res.cpuSystem).toFixed(2)+'%');
		    		  //$('#mem').attr('lay-percent',((res.memUsed/res.memTotal)*100).toFixed(2)+'%');
		    		  //$('#swap').attr('lay-percent',((res.swapUsed/res.swapTotal)*100).toFixed(2)+'%');
		    		  //element.render();
				  }
		    	});
			/** 顶部toolbar事件 **/
	    	table.on('toolbar(table)', function(obj){
	    		switch(obj.event){
	    		  case 'refresh-opt':
	  			    tableObj.reload();
	  			  	break;
	    		}
	    	});
	    	var g_data;
			table.on('tool(table)',function(obj){
				g_data = obj.data;
				switch(obj.event){
	    		  case 'view-opt':
	    			if(g_data.command != 'java'){
	    			  $('#gc-fieldset').addClass('layui-hide');
	    			} else {
	    			  $('#gc-fieldset').removeClass('layui-hide');
	    			}
	    			layer.open({
	    				  type: 1,
	    				  area: ['1050px','750px'],
	    				  title : '进程信息',
	    				  content: $('#windows'),
	    				  shadeClose : true,
	    				  btn : [ '确定' ],
	    				  success : function(layero, index){
	    					  fillWinForm();
	    				  },
	  				  yes : function(index, layero) {
	  					  layer.closeAll();
	  				  }
	    			});
	    			break;
	    		}
			});
			function fillWinForm(){
				$('#win-form')[0].reset();
				if(g_data == undefined){
					return;
				}
				$.post(
				  "/boss/linux/jstat/gc",
				  {pid:g_data.pid},
				  function(data, textStatus, jqXHR){
					  $('#s0').attr('lay-percent',((data.s0u/data.s0c)*100).toFixed(2)+'%');
					  $('#s0c').html((data.s0c/1024).toFixed(2)+" M");
					  $('#s1').attr('lay-percent',((data.s1u/data.s1c)*100).toFixed(2)+'%');
					  $('#s1c').html((data.s1c/1024).toFixed(2)+" M");
					  
					  $('#eden').attr('lay-percent',((data.eu/data.ec)*100).toFixed(2)+'%');
					  $('#ec').html((data.ec/1024).toFixed(2)+" M");
					  
					  $('#old').attr('lay-percent',((data.ou/data.oc)*100).toFixed(2)+'%');
					  $('#oc').html((data.oc/1024).toFixed(2)+" M");
					  
					  $('#method').attr('lay-percent',((data.mu/data.mc)*100).toFixed(2)+'%');
					  $('#mc').html((data.ccsc/1024).toFixed(2)+" M");
					  
					  $('#ccs').attr('lay-percent',((data.ccsu/data.ccsc)*100).toFixed(2)+'%');
					  $('#ccsc').html((data.ccsc/1024).toFixed(2)+" M");
					  
					  $('#ygc').attr('value',data.ygc);
					  $('#ygct').attr('value',data.ygct+' 秒');
					  $('#fgc').attr('value',data.fgc);
					  $('#fgct').attr('value',data.fgct+' 秒');
					  $('#gct').attr('value',data.gct+' 秒');
						  element.render();
					  },"json");
			  	$.post(
					  "/boss/linux/processDetail",
					  {pid:g_data.pid},
					  function(data, textStatus, jqXHR){
						  $('#p-command').html(data.command);
						  $('#p-cpu').attr('value',data.cpu+' %');
						  $('#p-mem').attr('value',data.mem+' %');
						  $('#p-time').attr('value',data.time);
						  $('#p-start').attr('value',data.start);
						  $('#p-user').attr('value',data.user);
						  $('#p-tty').attr('value',data.tty);
					  },"json");
			}
	    	function isNum(val){
	    	　　if(val === "" || val ==null){
	    	        return false;
	    	　　}
	    	   if(!isNaN(val)){　　　　
	    	　　　 return true; 
	    	　　} else { 
	    	　　　　return false; 
	    	　　} 
	    	}
			setInterval(function(){
				$.post(
				    "/boss/linux/eth-speed",
				    function(data2, textStatus, jqXHR){
				        $.each(data2,function(index, field){
				        	if(field.name != 'lo'){
				        		<#list eths as item>
				    			<#if (item.name != "lo")>
				    			$('#eth-host-${item.name!}').html(field.inet+' - ');
				        		downOption_${item.name!}.series[0].data[0].value = (field.downPeerSecond/1024/1024).toFixed(2);
				        		downOption_${item.name!}.series[0].max = field.downSpeed;
				        		downChart.setOption(downOption_${item.name!},true);
				        		
				        		upOption_${item.name!}.series[0].data[0].value = (field.upPeerSecond/1024/1024).toFixed(2);
				        		upOption_${item.name!}.series[0].max = field.upSpeed;
				        		upChart.setOption(upOption_${item.name!},true);
				        		</#if>
				        		</#list>
				        	}
				        });
				    },"json");
				$.post(
					    "/boss/linux/topUsed",
					    function(data2, textStatus, jqXHR){
					    	$('#cpu').attr('lay-percent',data2.cpuUsed.toFixed(2)+'%');
					    	$('#mem').attr('lay-percent',data2.memUsed.toFixed(2)+'%');
					    	$('#swap').attr('lay-percent',data2.swapUsed.toFixed(2)+'%');
					    	element.render();
					    },"json");
				fillWinForm();
			},3000);
		});
	</script>
</body>
<!-- windows弹窗定义开始 -->
<div id="windows" style="display: none;">
	<form class="layui-form" id="win-form">
	<fieldset class="layui-elem-field">
		<legend>进程信息</legend>
		<div class="layui-field-box">
			<div class="layui-form-item">
		        <label class="layui-form-label">命令</label><div class="layui-input-block">
		            <textarea id="p-command" class="layui-textarea" placeholder="命令"></textarea>
		        </div>
		    </div>
	  		<div class="layui-form-item">
				<div class="layui-inline">
				  <label class="layui-form-label">CPU使用率</label><div class="layui-input-inline">
				  <input id="p-cpu" class="layui-input" type="text" autocomplete="off" readonly/>
				 </div>
				 </div>
				 <div class="layui-inline">
				   <label class="layui-form-label">内存使用率</label><div class="layui-input-inline">
				      <input id="p-mem" class="layui-input" type="text" autocomplete="off" readonly/>
				   </div>
				 </div>
	  		</div>
	  		<div class="layui-form-item">
				<div class="layui-inline">
				  <label class="layui-form-label">消耗CPU时间</label><div class="layui-input-inline">
				  <input id="p-time" class="layui-input" type="text" autocomplete="off" readonly/>
				 </div>
				 </div>
				 <div class="layui-inline">
				   <label class="layui-form-label">进程启动时间</label><div class="layui-input-inline">
				      <input id="p-start" class="layui-input" type="text" autocomplete="off" readonly/>
				   </div>
				 </div>
	  		</div>
	  		<div class="layui-form-item">
				<div class="layui-inline">
				  <label class="layui-form-label">所属用户</label><div class="layui-input-inline">
				  <input id="p-user" class="layui-input" type="text" autocomplete="off" readonly/>
				 </div>
				 </div>
				 <div class="layui-inline">
				   <label class="layui-form-label">控制终端</label><div class="layui-input-inline">
				      <input id="p-tty" class="layui-input" type="text" autocomplete="off" readonly/>
				   </div>
				 </div>
	  		</div>
	  	</div>
	</fieldset>
	<fieldset id="gc-fieldset" class="layui-elem-field">
	  <legend>JVM信息</legend>
	  <div class="layui-field-box">
	  <div class="layui-form-item">
		  <div class="layui-inline">
	        <div>S1：<span id="s0c"></span></div>
	        <div class="layui-progress layui-progress-big" lay-showPercent="yes">
			  <div id="s0" class="layui-progress-bar layui-bg-green" lay-percent="0%"></div>
			</div>
		  </div>
		  <div class="layui-inline">
			<div>S2：<span id="s1c"></span></div>
	        <div class="layui-progress layui-progress-big" lay-showPercent="yes">
			  <div id="s1" class="layui-progress-bar layui-bg-green" lay-percent="50%"></div>
			</div>
		  </div>
		  <div class="layui-inline">
		    <div>eden：<span id="ec"></span></div>
	        <div class="layui-progress layui-progress-big" lay-showPercent="yes">
			  <div id="eden" class="layui-progress-bar layui-bg-green" lay-percent="50%"></div>
			</div>
		  </div>
		  <div class="layui-inline">
		  	<div>老年代：<span id="oc"></span></div>
	        <div class="layui-progress layui-progress-big" lay-showPercent="yes">
			  <div id="old" class="layui-progress-bar layui-bg-green" lay-percent="50%"></div>
			</div>
		  </div>
		  <div class="layui-inline">
		  	<div>方法区：<span id="mc"></span></div>
	        <div class="layui-progress layui-progress-big" lay-showPercent="yes">
			  <div id="method" class="layui-progress-bar layui-bg-green" lay-percent="50%"></div>
			</div>
		  </div>
		  <div class="layui-inline">
		  	<div>压缩类：<span id="ccsc"></span></div>
	        <div class="layui-progress layui-progress-big" lay-showPercent="yes">
			  <div id="ccs" class="layui-progress-bar layui-bg-green" lay-percent="50%"></div>
			</div>
		  </div>
	  </div>
	  <div class="layui-form-item">
		<div class="layui-inline">
		  <label class="layui-form-label">年轻代回收次数</label><div class="layui-input-inline">
		  <input id="ygc" class="layui-input" type="text" autocomplete="off" readonly/>
		 </div>
		 </div>
		 <div class="layui-inline">
		   <label class="layui-form-label">年轻代回收耗时</label><div class="layui-input-inline">
		      <input id="ygct" class="layui-input" type="text" autocomplete="off" readonly/>
		   </div>
		 </div>
		</div>
		<div class="layui-form-item">
		  <div class="layui-inline">
		    <label class="layui-form-label">老年代回收次数</label><div class="layui-input-inline">
		    <input id="fgc" class="layui-input" type="text" autocomplete="off" readonly/>
		   </div>
		   </div>
		   <div class="layui-inline">
		     <label class="layui-form-label">老年代回收耗时</label>
		     <div class="layui-input-inline">
		       <input id="fgct" class="layui-input" type="text" autocomplete="off" readonly/>
		    </div>
		  </div>
		</div>
		<div class="layui-form-item">
		  <div class="layui-inline">
		    <label class="layui-form-label">垃圾回收总耗时</label><div class="layui-input-inline">
		    <input id="gct" class="layui-input" type="text" autocomplete="off" readonly/>
		   </div>
		   </div>
		</div>
	  </div>
	</fieldset>
	</form>
</div>
</html>